<?php

namespace App\Admin\Controllers;

use App\Models\Activity;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class ActivityController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('旅游活动管理')
            ->description('description')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('旅游活动详情')
            ->description('description')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('编辑旅游活动')
            ->description('description')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('新增旅游活动')
            ->description('description')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Activity);

        $grid->id('ID');
        $grid->title();
        $grid->describe()->limit(30);
        $grid->coverimage()->image('http://media.weijingguanjia.com/',36,36);
        $grid->tags()->using([1 => '已结束', 2 => '进行中',3=>'未开始'])->badge();
        $grid->watch();
        $grid->recommend()->switch([
            'on'  => ['value' => 1, 'text' => '推荐', 'color' => 'primary'],
            'off' => ['value' => 0, 'text' => '一般', 'color' => 'default'],
        ]);
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Activity::findOrFail($id));

        $show->id('ID');
        $show->created_at('Created at');
        $show->updated_at('Updated at');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Activity);

        $form->text('title','标题')->rules('required');
        $form->image('coverimage','封面图片')->rules('required');
        $form->text('describe','描述')->rules('required');
        $form->ueditor('content','内容')->rules('required');
        $form->select('tags','标签')->options(['1' => '已结束', '2'=> '进行中', '3'=> '未开始'])->rules('required');
        $form->switch('recommend');
        return $form;
    }
}
